/*
 *  Arrow
 *
 *  Created by David Giovannini on 1/5/07.
 *  Copyright 2007 Software by Jove. All rights reserved.
 *
 */
 
#ifndef SBJ_Interface_IRemora_h
#define SBJ_Interface_IRemora_h

#include <boost/noncopyable.hpp>

#include <hash_set>

namespace SBJ
{

/*
Class: IRemora

IRemora is simply a mixin name to allow Hosts to destroy instance of them.
This allows life cycle responsibilty to be injected into a class without the
class being aware of the specific instance types that it is deleting.

It just knows that it is a Host and it may have Remoras.
*/

class IRemora
{
public:
	IRemora ( void ) {}
	virtual ~IRemora( void ) {}
};

template < typename T >
class TRemora : public IRemora
{
public:
	TRemora( void ) {}
	TRemora( const T& v ) : m_v( v ) {}
	virtual ~TRemora( void ) {}
	T* operator -> ( void ) { return &m_v; };
	T& operator * ( void ) { return m_v; };
private:
	T m_v;
};

/*
Class: Host

Derive from this class to allow Remoras to attach. Any instance become
non-copyable as a side effect.

The remora list is not thread-safe.
*/

class Host : private boost::noncopyable
{
public:
	Host( void ) {}

	virtual ~Host ( void );

	virtual void attachRemora( IRemora* remora );

protected:
	void killOffRemoras( void );

private:
	stdext::hash_set< IRemora* > m_remoras;
};

}

#endif